package com.dqhl.community.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dqhl.community.R;

/**
 * Created by cheng on 2016/8/30.
 * 分享 popupwindow
 */
public class SharePopupWindow extends PopupWindow {

    private Fragment context;

    public SharePopupWindow(Fragment context, View.OnClickListener itemsOnClick) {
        this.context = context;
        LayoutInflater inflater = (LayoutInflater) context.getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View popupView = inflater.inflate(R.layout.popupwindow_share, null);

        TextView tvCircleOfFriends = (TextView) popupView.findViewById(R.id.tv_circle_of_friends);
        TextView tvWeixinFriends = (TextView) popupView.findViewById(R.id.tv_weixin_friends);
        TextView tvQQ = (TextView) popupView.findViewById(R.id.tv_qq);
        ImageView ivCancle = (ImageView) popupView.findViewById(R.id.iv_cancel);

        tvCircleOfFriends.setOnClickListener(itemsOnClick);
        tvWeixinFriends.setOnClickListener(itemsOnClick);
        tvQQ.setOnClickListener(itemsOnClick);
        ivCancle.setOnClickListener(itemsOnClick);

        setBackgroundDrawable(new ColorDrawable(0));
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setFocusable(true);
        setOutsideTouchable(true);
        setContentView(popupView);
        update();
    }

    /**
     * PopupWindow 的动画效果
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = context.getActivity().getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0+
        context.getActivity().getWindow().setAttributes(lp);
    }
}
